package com.gz.rocketmq.filter.sql;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

public class SqlProducer {

    public static void main(String[] args) throws Exception {
        // 实例化消息生产者Producer
        DefaultMQProducer producer = new DefaultMQProducer("rocketmq01");
        try {
            //连接NameServer
            producer.setNamesrvAddr("192.168.36.128:9876");
            producer.start();
            List<Message> messages = new ArrayList<Message>() {{
                add(new Message("filerSql", "tag01", "tag01".getBytes(StandardCharsets.UTF_8)) {{
                    putUserProperty("idx", "0");
                }});
                add(new Message("filerSql", "tag02", "tag02".getBytes(StandardCharsets.UTF_8)) {{
                    putUserProperty("idx", "1");
                }});
                add(new Message("filerSql", "tag03", "tag03".getBytes(StandardCharsets.UTF_8)) {{
                    putUserProperty("idx", "2");
                }});
            }};
            SendResult send = producer.send(messages);
            System.out.println(send);
        } finally {
            producer.shutdown();
        }
    }

}
